package org.gkolpu.validation.oval.basetypes;

import java.util.List;

import net.sf.oval.configuration.annotation.IsInvariant;
import net.sf.oval.constraint.AssertTrue;
import net.sf.oval.constraint.AssertValid;
import net.sf.oval.constraint.MaxLength;
import net.sf.oval.constraint.NotNull;
import net.sf.oval.constraint.ValidateWithMethod;

public class Employee {
	@NotNull(errorCode = "employee.firstname.notnull", profiles = { "MYPROFILE" })
	@MaxLength(value = 30, errorCode = "employee.firstname.maxlength")
	private String firstName;
	@NotNull(errorCode = "employee.lastname.notnull", profiles = { "MYPROFILE" })
	@MaxLength(value = 50, errorCode = "employee.lasttname.maxlength")
	private String lastName;
	// @AssertValid
	private Address address;
	// @AssertValid
	private Email email;
	@AssertValid
	@ValidateWithMethod(errorCode = "employee.phones.count", methodName = "isCheckPhonesCount", parameterType = List.class, profiles = { "MYPROFILE" })
	private List<Phone> phones;
	@IsInvariant
	@AssertTrue(errorCode = "employee.emailorphone.notnull", profiles = { "MYPROFILE" })
	private boolean isEmailOrPhoneSet() {
		if (email != null || phones != null) {
			return true;
		}
		return false;
	}

	private boolean isCheckPhonesCount(List list) {
		if (list.size() <= 3 && list.size() > 0) {
			return true;
		}
		return false;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Email getEmail() {
		return email;
	}

	public void setEmail(Email email) {
		this.email = email;
	}

	public List<Phone> getPhones() {
		return phones;
	}

	public void setPhones(List<Phone> phones) {
		this.phones = phones;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Override
	public String toString() {
		return "Employee [firstName=" + firstName + ", lastName=" + lastName
				+ ", address=" + address + ", email=" + email + ", phones="
				+ phones + "]";
	}
}
